package com.wandian.utils
{
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.system.ApplicationDomain;
	import flash.utils.Dictionary;

	public class Res
	{
		private static var domain:ApplicationDomain
		private static var cache:Dictionary=new Dictionary(true);

		public static function init(domain:ApplicationDomain):void
		{
			Res.domain=domain;
		}

		public static function get(name:String):BitmapData
		{
			trace("get BitmapData:"+name);
			var bd:BitmapData=cache[name]

			if (bd == null)
			{
				try
				{
					var _class:Class=Class(domain.getDefinition(name));
					if (_class == null)
					{
						trace("get BitmapData null:"+name);
						return null;
					}
					bd=new _class()
					cache[name]=bd;
				}
				catch (e:Error)
				{

				}
			}
			return bd;
		}

		public static function getMC(name:String):MovieClip
		{
			var mc:MovieClip=cache[name]
			if (mc == null)
			{
				var _class:Class=Class(domain.getDefinition(name));
				mc=new _class()
				cache[name]=mc;
			}
			return mc;
		}
	}
}
